package edu.zli.redis.service.impl;

import edu.zli.redis.bean.Grade;
import edu.zli.redis.bean.User;
import edu.zli.redis.service.CacheService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author ZerlindaLi create at 2021/12/15 14:37
 * @version 1.0.0
 * @description CacheServiceImpl
 */
@Service
public class CacheServiceImpl implements CacheService {
    @Override
    @Cacheable(value = "MyCache", key = "#id", cacheManager = "cacheManager")
    public User getNavegationURLs(Long id) {
        User user = User.buildUser(id);
        return user;
    }

    @Override
    @Cacheable(value = "MyCache", key = "'users'", cacheManager = "cacheManager")
    public List<User> getUserList() {
        List<User> users = User.buildUserList();

        return users;
    }

    @Override
    @Cacheable(value = "MyCache", key = "'grade:'+#id", cacheManager = "cacheManager")
    public Grade getGrade(Long id) {
        Grade grade = new Grade(id, "班级"+id, getUserList());
        return grade;
    }
}
